<?php


namespace App\Model\Logic;

use App\Exception\HttpException;
use App\Model\Dao\ConfigDao;
use Swoft\Bean\Annotation\Mapping\Bean;
use Swoft\Bean\Annotation\Mapping\Inject;

/**
 * Class ConfigLogic
 * @Bean(name="ConfigLogic")
 * @package App\Model\Logic
 */
class ConfigLogic
{
    /**
     * @Inject()
     * @var ConfigDao
     */
    private $configDao;

    public function saveData($data){
        //数据验证
        validate($data, 'ConfigValidator');
        //更新到数据表
        if ($this->configDao->updateCreate($data)){
            throw new HttpException('更新成功', 0);
        }
        throw new HttpException('更新失败');
    }

    /**
     * 获取配置信息
     * @return \App\Model\Entity\Config|null
     */
    public function getConfig(){
        return $this->configDao->getConfig();
    }
}
